﻿using System.Collections.Generic;
using System;
using System.Linq;
namespace Library.WebControls.SimpleGridView {
	public class ColumnTextValueCollection {
		private readonly SpGridView _gridView;
		internal readonly List<ColumnTextValue> ColumnValueTextList;
		public ColumnTextValueCollection(SpGridView gridView) {
			_gridView = gridView;
			ColumnValueTextList = new List<ColumnTextValue>();
		}
		public ColumnTextValue Add(int visibleColumnIndex, object value) {
			return Add(visibleColumnIndex, value, String.Empty);
		}
		public ColumnTextValue Add(int visibleColumnIndex, object value, string text) {
			return Add(_gridView.VisibleColumns[visibleColumnIndex], value, text);
		}
		public ColumnTextValue Add(string columnName, object value) {
			return Add(columnName, value, String.Empty);
		}
		public ColumnTextValue Add(string columnName, object value, string text) {
			return Add(_gridView.VisibleColumns.Find(columnName), value, text);
		}
		public ColumnTextValue Add(SpGvColumn column, object value) {
			return Add(column, value, String.Empty);
		}
		public ColumnTextValue Add(SpGvBaseColumn column, object value, string text) {
			ColumnTextValue c = ColumnValueTextList.FirstOrDefault(cl => cl.Column == column);
			if (c == null) {
				c = new ColumnTextValue(column);
				ColumnValueTextList.Add(c);
			}
			c.Value = value;
			c.DisplayText = text;

			return c;

		}
	}
}
